package com.pruebas.xmlsimple;

import java.io.InputStream;

import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.pruebas.xmlsimple.model.Competition;
import com.pruebas.xmlsimple.view.TeamListView;

public class XMLSimpleTestActivity extends Activity {
	
	private TextView name;
	private TextView fixtures;
	private TeamListView listView;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        name = (TextView) findViewById(R.id.competition_name);
        fixtures = (TextView) findViewById(R.id.competition_fixtures);
        listView = (TeamListView) findViewById(R.id.listview);
        
        Competition competition = deserealizeXML();
        name.setText(competition.getName());
        fixtures.setText(competition.getFixtures());
        listView.setTeamList(competition.getTeams());
        
    }

	private Competition deserealizeXML() {
		Competition response = new Competition();
		InputStream result = getResources().openRawResource(R.raw.example);
		try {
			Serializer serializer = new Persister();
			response = serializer.read(Competition.class, result);
		} catch (Exception e) {
			Log.e("ERROR XMLSIMPLE", e.getMessage());
		}
		return response;
	}
}